
package system.base;

import java.util.List;

import system.data.CompanyMessageData;
import system.data.WarehousePageData;
import client.XMLSend;

import com.hitrust.gs.dao.GSCompanyMessageDao;
import com.hitrust.gs.dao.GSOrderCategoryDAO;

import framework.core.Conditions;
import framework.core.ConstDefine;
import framework.core.DBConnection;
import framework.core.DateUtil;
import framework.core.IHandler;
import framework.core.ILoginContext;
import framework.core.Logger;
import framework.core.ObjectList;
import framework.core.PageData;
import framework.core.SearchEvent;
import framework.core.SrvContext;
import framework.core.Value;
/*
	Author    :justin
	CreateTime:2007-12-13 17:36:20
*/
public class CompanyMessageSrv extends IHandler
{

	public CompanyMessageSrv() 
	{
		super();
	}

	private void backListCompanyMessage(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"CompanyMessage.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		if(action_code.equalsIgnoreCase("listCompanyMessage"))
		{
			listCompanyMessage(con,context,loginContext,path);
			return;
		}
		
		if(action_code.equalsIgnoreCase("toUpdateCompanyMessage"))
		{
			GSCompanyMessageDao dao = new GSCompanyMessageDao();
			String code = context.getString("Id",null);
			List lss = dao.queryCompanyMessage(code);
			CompanyMessageData cmd=new CompanyMessageData();
			if(lss.size()!=0){
			cmd = (CompanyMessageData)lss.get(0);
			}
			context.setValue("CompanyMessageData",cmd);
			context.setNextUrl(path+"CompanyMessageEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("backListCompanyMessage"))
		{
			backListCompanyMessage(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveCompanyMessage"))
		{
			context.setErrorUrl(path+"CompanyMessageEdit.jsp");
			saveCompanyMessage(con,context,loginContext);
			//Warehouse obj = Warehouse.fetch();
			backListCompanyMessage(con,context,path);	
			return;
		}
		
		Logger.throwException("CompanyMessageSrv","unknown action_code="+action_code);
	}
	
	//保存  营运公司税务信息
    private void saveCompanyMessage(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
    {
        String warehouseCode = context.getString("m_Code",null);
        GSCompanyMessageDao dao= new GSCompanyMessageDao();
        List lss = dao.queryCompanyMessageIsOk(warehouseCode);
        CompanyMessageData cmd = new CompanyMessageData();
        cmd.setWarehouseCode(warehouseCode);
        cmd.setCustomerName(context.getString("m_Name",null));
        cmd.setCustomerTax(context.getString("m_Tax",null));
        cmd.setCustomerAddress(context.getString("m_Address",null));
        cmd.setCustomerPhone(context.getString("m_Phone",null));
        cmd.setCustomerBand(context.getString("m_Band",null));
        cmd.setCustomerUser(context.getString("m_User",null));
        if(lss.size()>0){
        	dao.update(warehouseCode,cmd);
        }else{
        	dao.insert(cmd);
        }
    }
	
	private void listCompanyMessage(DBConnection con,SrvContext context,ILoginContext loginContext,String path) throws Exception
	{
		WarehouseSearchEvent event = (WarehouseSearchEvent)SearchEvent.fromForm(context,WarehouseSearchEvent.class);
		event.setWarehouseCodeUser(ConstDefine.getWildCard(loginContext.getLoginWarehouseCode()));
		context.setSessionValue("WarehouseSearchEvent",event);
		context.setNextUrl(path+"CompanyMessage.jsp");
	}
	
	

}
